<?php

namespace App\Admin\Controllers;

use App\Models\Supplier;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Controllers\AdminController;

class SupplierController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Supplier(), function (Grid $grid) {
            $grid->id->sortable();
            $grid->name;
            $grid->contact_phone;
            $grid->contact_name;
            $grid->contact_address;
            $grid->description->hide();
            $grid->status->display(function ($value) {
                return $value ? "是" : "否";
            });
            $grid->created_at;
            $grid->updated_at->sortable();

            $grid->actions(function ($actions) {
                $actions->disableView();
            });
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
        
            });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Supplier(), function (Form $form) {
            $form->display('id');
            $form->text('name');
            $form->text('contact_phone');
            $form->text('contact_name');
            $form->text('contact_address');
            $form->text('description');
            $form->number('sort');
            $form->radio('status')->options([0 => '禁用', 1 => '开启']);
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
